package com.studypavilion.project;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class UI extends AppCompatActivity implements View.OnClickListener {
    private Button btn_login, btn_exit;
    private EditText edtName, edtPasswd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ui);

        edtName = findViewById(R.id.edtName);
        edtPasswd = findViewById(R.id.edtPasswd);

        btn_login = findViewById(R.id.btn_login);
        btn_exit = findViewById(R.id.btn_exit);

        btn_login.setOnClickListener(this);
        btn_exit.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.btn_login:

                String name = edtName.getText().toString();
                String passwd = edtPasswd.getText().toString();

                if (name.isEmpty() || passwd.isEmpty()) {
                    Toast.makeText(UI.this, "请输入用户名或密码", Toast.LENGTH_LONG).show();
                } else if (name.equals("abc") && passwd.equals("123")) {
                    Toast.makeText(this, "正确", Toast.LENGTH_LONG).show();
                    Intent form = new Intent(UI.this, MainActivity.class);
                    //跳转界面
                    startActivity(form);

                } else {
                    Toast.makeText(UI.this, "用户名或密码错误", Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.btn_exit:
                System.exit(0);
                break;


//        Intent intent = new Intent(UI.this, MainActivity.class);
//        startActivity(intent);

        }
    }
}